package org.jeecg.modules.smartSchoolScholarship.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.smartSchoolScholarship.entity.SmartSchoolScholarship;
import org.jeecg.modules.smartSchoolScholarship.mapper.SmartSchoolScholarshipMapper;
import org.jeecg.modules.smartSchoolScholarship.service.ISmartSchoolScholarshipService;
import org.jeecg.modules.smartTeacher.entity.SmartSchoolTeacherInfomation;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 奖学金申请表
 * @Author: jeecg-boot
 * @Date:   2022-01-17
 * @Version: V1.0
 */
@Service
public class SmartSchoolScholarshipServiceImpl extends ServiceImpl<SmartSchoolScholarshipMapper, SmartSchoolScholarship> implements ISmartSchoolScholarshipService {

    @Override
    public void saveOrUpdateInfo(JSONArray form_component_values, String originator_userid) {
        {
            SmartSchoolScholarship teacher = new SmartSchoolScholarship();
            for (int i = 0; i < form_component_values.size(); i++) {
                JSONObject jsonObject = form_component_values.getJSONObject(i);
                String name = jsonObject.getString("name");
                String value = jsonObject.getString("value");
                switch (name){
                    case "姓名":
                        teacher.setStudentName(value);
                        break;
                    case "学号":
                        teacher.setStudentNumber(value);
                        break;
                    case "系别":
                        teacher.setStudentDepartment(value);
                        break;
                    case "性别":
                        teacher.setStudentSex(value);
                        break;
                    case "专业":
                        teacher.setStudentMajor(value);
                        break;
                    case "专业排名":
                        teacher.setProfessionalRanks(value);
                        break;
                    case "平均学分绩点":
                        teacher.setCreditGradePoint(value);
                        break;
                }
            }
            teacher.setId(originator_userid);

            List<SmartSchoolScholarship> diyStudents = baseMapper.selectList(new LambdaQueryWrapper<SmartSchoolScholarship>().eq(SmartSchoolScholarship::getId, teacher.getId()));
            if (diyStudents!=null && diyStudents.size()>0){
                baseMapper.update(teacher,new LambdaQueryWrapper<SmartSchoolScholarship>().eq(SmartSchoolScholarship::getId,teacher.getId()));
            }else {
                baseMapper.insert(teacher);
            }
        }

    }
}
